<%@page import="systems.AdsSystem"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="helpers.StringHelper"%>
<%@page import="entities.User"%>
<%@page import="java.util.TreeMap"%>
<%@page import="entities.Article"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
Article article = (Article) request.getAttribute("article");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String success = (String)request.getAttribute("success");
User user = (User) request.getAttribute("user_logged_in");
String url = (String) request.getAttribute("url");

//Set content for seo
String nameServer = UrlHelper.getDomainServer(request);
TreeMap<String, String> params = new TreeMap<String, String>();
params.put("NAMESERVER__", nameServer);

String title = LanguageHelper.getString("submit_article_title") + " - " + nameServer;
String description = StringHelper.replace(LanguageHelper.getString("submit_article_description"), params);
String keywords = LanguageHelper.getString("submit_article_keywords");
String urlSeo = UrlHelper.getServerUrl(request) + "/submit-article";
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="<%=title %>" />
    <jsp:param name="description" value="<%=description %>" />
    <jsp:param name="keywords" value="<%=keywords %>" />
    <jsp:param name="ogtitle" value="<%=title %>" />
    <jsp:param name="ogurl" value="<%=urlSeo %>" />
    <jsp:param name="ogdescription" value="<%=description%>" />
</jsp:include>

<script src="/sources/ckeditor/ckeditor.js"></script>
		
            <div id="mainContent" class="left">
                <div id="editArticlePage">
                	<h3 class="title"><%=LanguageHelper.getString("submit_title")%></h3>
                	<div class="adv">
						<%=AdsSystem.getAds468x15() %>
	                </div>
                	<% if (success != null) { %>
                	<div class="messageBox-success"><%=success %></div>
                	<% } %>
					<form method="post" action="" class="formStyle">
						<% if (user == null) { %>
						<div class="left <%=check.get("name") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_author_name")%>&nbsp; (<%=LanguageHelper.getString("required")%>)</label>
                            <input type="text" name="name" value="<%=article.getAuthorName() %>"/>
                            <% if (check.get("name") != null) { %>
                            <p class="errorMessage"><%=check.get("name") %></p>
                            <% } %>
                        </div>
                        <div class="right <%=check.get("email") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_author_email")%>&nbsp; (<%=LanguageHelper.getString("required")%>)</label>
                            <input type="text" name="email" value="<%=article.getEmail() %>"/>
                            <% if (check.get("email") != null) { %>
                            <p class="errorMessage"><%=check.get("email") %></p>
                            <% } %>
                        </div>                                                
                        <div class="clearbreak"></div>
						<% } %>
						
                        <div class="left <%=check.get("title") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_article_title")%>&nbsp; (<%=LanguageHelper.getString("required")%>)</label>
                            <input type="text" name="title" value="<%=article.getTitle() %>"/>
                            <% if (check.get("title") != null) { %>
                            <p class="errorMessage"><%=check.get("title") %></p>
                            <% } %>
                        </div>
                        <div class="right <%=check.get("category") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_category")%>&nbsp; (<%=LanguageHelper.getString("required")%>)</label>
                            <select name="category">
                            	<% for (Category category : categories) { %>                                
                                <option value="<%=category.getId()%>" <%=category.getId().equalsIgnoreCase(article.getCategory()) ? "selected=\"selected\"" : "" %>><%=category.getName() %></option>
                                <% } %>
                            </select>
                            <% if (check.get("category") != null) { %>
                            <p class="errorMessage"><%=check.get("category") %></p>
                            <% } %>
                        </div>                                                
                        <div class="clearbreak"></div>
                        <div class="<%=check.get("content") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_content")%>&nbsp; (<%=LanguageHelper.getString("required")%>)</label>
                            <textarea name="content" class="ckeditor"><%=article.getContent() %></textarea>
                            <% if (check.get("content") != null) { %>
                            <p class="errorMessage"><%=check.get("content") %></p>
                            <% } else { %>
                            <p class="note"><%=LanguageHelper.getString("note_content")%></p>
                            <% } %>
                        </div>
                        <div class="keyword <%=check.get("keywords") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_keyword")%></label>
                            <input type="text" name="keywords" value="<%=StringHelper.listToString(article.getKeywords(), ", ")%>"/>
                            <% if (check.get("keywords") != null) { %>
                            <p class="errorMessage"><%=check.get("keywords") %></p>
                            <% } else { %>
                            <p class="note"><%=LanguageHelper.getString("example_keyword")%></p>
                            <% } %>
                        </div>
                        <div class="clearbreak"></div>
                        
                        <% if (user == null) { %>
                        <div class="keyword <%=check.get("website") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_author_website")%></label>
                            <input type="text" name="website" value="<%=url != null ? url : article.getWebsite()%>"/>
                            <% if (check.get("website") != null) { %>
                            <p class="errorMessage"><%=check.get("website") %></p>
                            <% }%>
                        </div>
                        
                        <div class="keywords <%=check.get("captcha") != null ? "error" : ""%>">
                        	<label><%=LanguageHelper.getString("label_security_code")%> &nbsp; (<a href="/login"><%=LanguageHelper.getString("login")%></a> <%=LanguageHelper.getString("to_remove_captcha")%>)</label>
                        	<script>
					        	var RecaptchaOptions = { theme : 'red'};
					  		</script>
							<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LeA0c4SAAAAAMsdjrB49GPol6XImTdJM2U2AHrF"></script>
							
							<% if (check.get("captcha") != null) { %>
                            <p class="errorMessage"><%=check.get("captcha") %></p>
                            <% } %>
                        </div>
                        <% } %>
                        <div class="clearafter">
                        	<button type="submit"><%=LanguageHelper.getString("save")%></button>
                        	<div class="right">
                        		<%=AdsSystem.getAds468x60() %>
                        	</div>
                        </div>
                    </form>
                </div>
            </div>
            
            <jsp:include page="/elements/right.jsp" />
            
            <div class="clearbreak"></div>
<jsp:include page="/layouts/footer.jsp" />